package com.ch.home.controller.gameController;

import com.ch.home.bean.GameInfo;
import com.ch.home.service.serviceImpl.gameServiceImpl.GameInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * Created by CHEN on 2019/8/30.
 */
@RestController
@RequestMapping("/game/result")
public class GameResultController {


    @Autowired
    GameInfoServiceImpl gameInfoService;


    @PostMapping("/sendResult")
    public HashMap addGameResult(@RequestParam(required = false) Integer game_name_id,
                                 @RequestParam(required = false) Integer player1_id,
                                 @RequestParam(required = false) Integer player1_score,
                                 @RequestParam(required = false) Integer player2_id,
                                 @RequestParam(required = false) Integer player2_score
    ) {
        HashMap<Object, Object> result;
        GameInfo gameInfo = new GameInfo(null, game_name_id, player1_id, player1_score, player2_id, player2_score, null, null, null);
        result = gameInfoService.addResult(gameInfo);
        return result;
    }


    @PostMapping("/updateResult")
    public HashMap updateGameResult(@RequestParam(required = false) Integer game_id,
                                    @RequestParam(required = false) Integer game_name_id,
                                    @RequestParam(required = false) Integer player1_id,
                                    @RequestParam(required = false) Integer player1_score,
                                    @RequestParam(required = false) Integer player2_id,
                                    @RequestParam(required = false) Integer player2_score) {

        HashMap<Object, Object> result;

        GameInfo gameInfo = new GameInfo(game_id, game_name_id, player1_id, player1_score, player2_id, player2_score, null, null, null);
        result = gameInfoService.updateResult(gameInfo);
        return result;
    }

    @PostMapping("/getResult")
    public HashMap getGameResultByCondition(@RequestParam(required = false) Integer game_id,
                                            @RequestParam(required = false) Integer game_name_id,
                                            @RequestParam(required = false) Integer player1_id,
                                            @RequestParam(required = false) Integer player2_id,
                                            @RequestParam(required = false) Integer winner
                                            ) {

        HashMap<Object, Object> result;
        GameInfo gameInfo = new GameInfo(game_id, game_name_id, player1_id, null, player2_id, null, null, winner, null);
        result = gameInfoService.getGameResultByCondition(gameInfo);
        return result;
    }

}
